package Controller;

import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JEditorPane;

/**
 *
 * @author pieterc
 */
public class PostAction extends AbstractAction implements IAction {

    public PostAction() {
        super("Post!");
    }

    public static String removeHTML(String htmlString) {
        // Remove HTML tag from java String    
        String noHTMLString = htmlString.replaceAll("\\<.*?\\>", "");

        // Remove Carriage return from java String
        noHTMLString = noHTMLString.replaceAll("\r", "");

        // Remove New line from java string and replace html break
        noHTMLString = noHTMLString.replaceAll("\n", "");
        noHTMLString = noHTMLString.replaceAll("\'", "&#39;");
        noHTMLString = noHTMLString.replaceAll("\"", "&quot;");
        return noHTMLString.trim();
    }

    public void actionPerformed(ActionEvent e) {
        //hmmmmmmm
        JEditorPane jep = (JEditorPane) ((JButton) e.getSource()).getParent().getComponent(0);
        ActionManager.getRemote().postStatus(removeHTML(jep.getText()));
        jep.setText("");
    }
}
